home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CUJ9209.ARJ / 1009024A < prev    next >
Text File  |  1992-07-08  |  842b  |  48 lines

  1. // LISTING 4
  2.  
  3. #ifndef EXH_H
  4. #define EXH_H
  5.  
  6. #include <mem.h>
  7. #include <string.h>
  8. #include "JmpStack.h"
  9. #include "Exception.h"
  10.  
  11. typedef void(*PFV)();
  12. extern void terminate();
  13. extern PFV set_terminate(PFV);
  14. extern void unexpected();
  15. extern PFV set_unexpected(PFV);
  16.  
  17. class ExH {
  18. public:
  19.     enum {BUFSIZE=2024};
  20.  
  21. private:
  22.     friend PFV set_terminate(PFV);
  23.     friend PFV set_unexpected(PFV);
  24.     friend void terminate();
  25.     friend void unexpected();
  26.     static PFV terminate;
  27.     static PFV unexpected;
  28.  
  29.     static char safeSpace[BUFSIZE];
  30.  
  31. public:
  32.     static Exception* lastEx;    // Pointer to safeSpace
  33.     static JmpStack stk;
  34.     static void throw(Exception&);
  35. };
  36.  
  37. inline void ExH::throw (Exception& ex)
  38. {
  39.     // Copy exception to a safe place
  40.     if(ExH::lastEx != &ex)
  41.         memcpy(ExH::safeSpace, &ex, ex.size());
  42.  
  43.     // longjmp to last try
  44.     longjmp(ExH::stk--, ex.type());
  45. }
  46.  
  47. #endif
  48.